package com.platform.boot.security.tenant.member;

import com.platform.boot.utils.CriteriaUtils;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.beans.BeanUtils;
import org.springframework.data.relational.core.query.Criteria;

import java.util.Set;

/**
 * @author <a href="https://github.com/vnobo">Alex bob</a>
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class TenantMemberRequest extends TenantMember {

    @NotNull(message = "用户[users]不能为空!")
    private Set<String> users;

    public static TenantMemberRequest withUserCode(String userCode) {
        TenantMemberRequest request = new TenantMemberRequest();
        request.setUserCode(userCode);
        return request;
    }

    public static TenantMemberRequest of(String tenantCode, String userCode) {
        TenantMemberRequest request = withUserCode(userCode);
        request.setTenantCode(tenantCode);
        return request;
    }

    public TenantMember toMemberTenant() {
        TenantMember tenantMember = new TenantMember();
        BeanUtils.copyProperties(this, tenantMember);
        return tenantMember;
    }

    public Criteria toCriteria() {
        return CriteriaUtils.build(this);
    }

}